#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
char *trim(const char *str) {
    const char *p=str;
    char *new_str;
    size_t new_size;
    uint64_t start_index=0;
    uint64_t end_index=0;
    uint64_t current_index=0;

    uint8_t mode=0;

    while (*str) {
        if (
            *str=='\0'
            || *str==' '
            || *str=='\t'
            || *str=='\n'
        ) {
            if (mode==0) {
                ++start_index;
            }
        } else {
            end_index=current_index;
            if (mode==0) {
                mode=1;
            }
        }
        ++current_index;
        ++str;
    }
    if (end_index==0) {
        new_size=0;
    } else {
        new_size=end_index-start_index+1;
    }
    new_str=malloc(new_size+1);
    memcpy(new_str,&(p[start_index]),new_size);
    new_str[new_size]='\0';
    return new_str;
}
